package com.zhilingshenghuo.app.zhly.utils;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;

import java.io.IOException;

public class PlayerUtils {
    AssetManager assetManager;
    MediaPlayer player = null;
    private Context context;

    public PlayerUtils(Context context) {
        this.context = context;
    }

    public void playerPath(String path){
        player = new MediaPlayer();
        assetManager = context.getResources().getAssets();
        try {
            AssetFileDescriptor fileDescriptor = assetManager.openFd(path);
            player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getStartOffset());
            player.prepare();
            player.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void destoryPlayer(){
        player.stop();
        player.release();
    }
}
